package com.dwk.rabbitMQ1;

import com.rabbitmq.client.*;

public class Consumer {
    private final static String QUEUE_NAME = "hello";
    //接收消息
    public static void main(String[] args) throws Exception {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("47.94.143.117");
        factory.setUsername("admin");
        factory.setPassword("123");

        Connection connection=factory.newConnection();
        Channel channel = connection.createChannel();

        DeliverCallback deliverCallback=(consumerTag,message) ->{
            System.out.println(new String(message.getBody()));
        };

        CancelCallback cancelCallback= var1 ->{
            System.out.println("消息消费被中断");
        };

        //消费者接收消息
        /**
         * 1.消费哪个队列
         * 2.是否要自动应答
         * 3.消费者未成功回调
         * 4.消费者取消消费的回调
         */
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback );

    }
}
